/**
 * @author daniele.gili@usi.ch
 */

package ch.usi.inf.pf2;

import java.awt.Graphics;

public class MegaOutput extends CommonGate implements java.io.Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private boolean compiling;
	private int sampleTime;

	public MegaOutput(int x, int y, int pos) {

		this.x = x - getWidth() / 4;
		this.y = y - getHeight() / 4;
		this.height = getHeight() / 3;
		this.width = getWidth() / 3;

		this.pos = pos;
		sampleTime = 3000;
	}

	public int getSampleTime() {
		return sampleTime;
	}

	public void setNewTime(int sampleTime) {
		this.sampleTime = sampleTime;
	}

	
	public Integer getValue(int index){
		return inputList.get(0).getValue(index);
	}
	

	
	public void getOutput(int index) {
		actualValue = inputList.get(0).getValue(index);
		System.out.println("exit value: " + actualValue);
		// I use the "try" to make the reading on the output periodic (every
		// 100ms for now)
		

	}

	public void notifyCompiling(boolean compiling) {
		this.setCompiling(compiling);
	}

	public void draw(final Graphics g) {
		g.drawOval(x, y, width, height);
		if (actualValue == new Integer(0)) {
			g.drawString("0", x, y);}
			else if (actualValue == new Integer(1)){
			g.drawString("1", x, y);}
			else g.drawString("null", x, y);
		}
		
	

	public void setCompiling(boolean compiling) {
		this.compiling = compiling;
	}

	public boolean isCompiling() {
		return compiling;
	}

}
